<template>
  <div style="height:100%;width:100%;position:relative;">
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="poptitle" :visible.sync="dialogTableVisible" @close="popcommonclose" v-if="dialogTableVisible" ref="popcommondialog">
          <rm-pop-common @cancel="dialogTableVisible=false,popcommonclose()" :datatype="popdatatype" :rptunitid="selLibrid" @change="popchange" ref="popcommon"></rm-pop-common>
          <!--SMP210_xxx specimen-->
      </el-dialog>
      <div class="pagetop">
          <div style="width:100%">
              <div style="float:left;width:100%; bottom: 4vw;" >
                  <table style=" width:100%; float:left;  overflow:hidden; border-spacing:3px;"  cellpadding="0" cellspacing="0" >
                      <tr style="width:100%;">
                          <span class="sepcnoDate">
                          <td  style="height:21px; overflow:hidden"  >
                              <!-- <td  style="height:21px;width:60px; "  RegisterSeq > -->
                              <div style="color:#0095d9;height:21px;overflow:hidden">
                                  开始日期
                              </div>
                          </td>
                          <td style="width: 120px;height:21px;overflow:hidden" >
                              <el-date-picker v-model="startdate"   value-format="yyyy-MM-dd" :picker-options="pickerOptions" :clearable="false"  style="width:100%; " ></el-date-picker>
                          </td>
                          <td  style="height:21px; overflow:hidden"  >
                              <!-- <td  style="height:21px;width:60px; "  RegisterSeq > -->
                              <div style="color:#0095d9;height:21px;overflow:hidden">
                                  结束日期
                              </div>
                          </td>
                          <td style="width: 120px;height:21px;overflow:hidden" >
                              <el-date-picker v-model="enddate"   value-format="yyyy-MM-dd" :picker-options="pickerOptions" :clearable="false"  style="width:100%; " ></el-date-picker>
                          </td>
                          </span>
                          <span ref="SampleBankWidth">
                          <td  style="color:#0095d9;height:21px;overflow:hidden">
                              <div style="text-align:right;">
                                  样本库
                              </div>
                          </td>
                          <td  style="width: 120px;height:21px;overflow:hidden">
                              <el-select v-model="selLibrid" filterable style="width:100%;"  ref="selLibrid" @change="LibridChange()">
                                  <!-- <el-option v-for="(item, index) in selSmpLibrary_Options" :key="index" :value="item.librname" :label="item.librid"></el-option> -->
                                  <el-option v-for="(item, index) in selSmpLibrary_Options" :key="index" :value="item.librid" :label="item.librname" ></el-option>
                              </el-select>
                          </td>
                          <td style="float:right;overflow:hidden">
                              <el-button icon="el-icon-upload2" v-has="'PEXPORT'" @click="BtnExport()">导出</el-button>
                          </td>
                          <td style="float:right;overflow:hidden">
                              <el-button icon="el-icon-refresh-right" @click="BtnPrint()">打印</el-button>
                          </td>
                          <td style="float:right;overflow:hidden">
                              <el-button icon="el-icon-delete" v-has="'PDELETE'" @click="BtnDelete()" >删除</el-button>
                          </td>
                          <td style="float:right;overflow:hidden">
                              <el-button icon="el-icon-search" type="primary" v-has="'PINQUERY'" @click="smpRegisterQuery()">查询</el-button>
                          </td>
                          </span>
                      </tr>


                  </table>
              </div>
              <div style="float:left;width:100%;">
              <table style="float:left;  overflow:hidden; border-spacing:3px; table-layout:fixed" class="tableleft" ref="xTableDiv">
                      <tr v-for="(cols,index) in ColTotalData" :key="index" style="width:100%; display:block; margin:2px 0; height:26px;" >
                          <!-- <span v-for="(item,index2) in cols" :key="item.col_code"  v-show="item.visibled" style="display:block: width:100px;overflow:hidden;text-overflow:ellipsis;"> -->
                              <span v-for="(item,index2) in cols" :key="item.col_code"  v-show="item.visibled" style="display:block: width:100px;overflow:hidden;text-overflow:ellipsis;">
                          <td  style="height:21px; " :style="{width: HisTdWidth[index2] + 'px'}">
                              <div  style="text-overflow: ellipsis; overflow: hidden; white-space: nowrap;text-align:right;">
                                      {{item.col_label}}
                              </div>
                              </td>
                          <td style="width: 120px;height:21px; " >
                              <!-- <el-input v-model="PatientInfo[item.col_code]" v-if="item.col_code==='pat_ageyear'" type="text"  size="mini" :readonly="true" :disabled="true" :ref="item.col_code" ></el-input> -->
                              <div v-if="item.valuetype=='1'" >
                              <el-radio-group v-if="item.col_code=='istransfer'"  v-model="PatientInfo[item.col_code]" :ref="item.col_code" v-show="item.visibled" onkeydown="if(event.keyCode==9){event.returnValue=false;} " @keyup.tab.native="EnterEvent(item.col_code)"   >
                              <el-radio-button  :label="'1'"  style="vertical-align: middle;" >是</el-radio-button>
                              <el-radio-button  :label="'0'"  style="vertical-align: middle;" >否</el-radio-button>
                              </el-radio-group>
                              <el-radio-group v-if="item.col_code=='isoperation'" v-model="PatientInfo[item.col_code]" :ref="item.col_code" v-show="item.visibled" onkeydown="if(event.keyCode==9){event.returnValue=false;} " @keyup.tab.native="EnterEvent(item.col_code)"  >
                              <el-radio-button  :label="'1'"  style="vertical-align: middle;" >是</el-radio-button>
                              <el-radio-button  :label="'0'"  style="vertical-align: middle;" >否</el-radio-button>
                              </el-radio-group>
                              <el-radio-group v-if="item.col_code=='antivirus'" v-model="PatientInfo[item.col_code]" :ref="item.col_code" v-show="item.visibled" onkeydown="if(event.keyCode==9){event.returnValue=false;} " @keyup.tab.native="EnterEvent(item.col_code)"  >
                              <el-radio-button  :label="'1'"  style="vertical-align: middle;" >是</el-radio-button>
                              <el-radio-button  :label="'0'"  style="vertical-align: middle;" >否</el-radio-button>
                              </el-radio-group>
                              <!-- <el-input v-model="PatientInfo[item.col_code]"  type="text" size="mini" :ref="item.col_code" v-show="item.visibled" :readonly="item.noedit"   @keyup.enter.native="EnterEvent(item.col_code)" @keyup.space.native="SpaceEvent(item.col_code)" @keyup.up.native="InputMove(0, item.col_code)" @keyup.down.native="InputMove(1, item.col_code)"  @focus="InputFocus(item.col_code)" @dblclick.native="inputdblEvent(item.col_code)" @change="popinputchange($event,item.col_code)" ></el-input> -->
                              </div>
                              <div  v-else-if="item.valuetype=='2'">
                                      <el-input v-model="PatientInfo[item.col_code]" v-if="item.col_code=='smp_registerno'" type="text"  size="mini" v-show="item.visibled" :readonly="true" :disabled="true" :ref="item.col_code"  @keyup.enter.native="EnterEvent(item.col_code)" ></el-input>
                                      <el-input v-model="PatientInfo[item.col_code]" v-else-if="item.col_code === 'pat_agestr'" @keyup.enter.native="EnterEvent(item.col_code)" v-show="item.visibled" :disabled="!item.enabled"  @keyup.space.native="SpaceEvent(item.col_code)" @keyup.up.native="InputMove(0, item.col_code)" @keyup.down.native="InputMove(1, item.col_code)" @dblclick.native="inputdblEvent(item.col_code)" @change="popinputchange($event, item.col_code)" @focus="InputFocus(item.col_code)" :readonly="item.noedit"  size="mini" :ref="item.col_code"></el-input>
                                      <el-input v-model="PatientInfo[item.col_code]" v-else-if="item.col_code === 'req_reason'" @keyup.enter.native="EnterEvent(item.col_code)" v-show="item.visibled" :disabled="!item.enabled"  @keyup.space.native="SpaceEvent(item.col_code)" @keyup.up.native="InputMove(0, item.col_code)" @keyup.down.native="InputMove(1, item.col_code)" @dblclick.native="inputdblEvent(item.col_code)" @focus="InputFocus(item.col_code)"  size="mini" :ref="item.col_code"></el-input>
                                      <el-input v-model="PatientInfo[item.col_code]" v-else-if="item.col_code!='smp_registerno'" type="text"  size="mini" v-show="item.visibled"  :ref="item.col_code" :disabled="!item.enabled"  @keyup.enter.native="EnterEvent(item.col_code)"  @change="inputChangeEvent($event,item.col_code)" @keyup.up.native="InputMove(0,item.col_code)" @keyup.down.native="InputMove(1,item.col_code)" @focus="InputFocus(item.col_code)" ></el-input>

                              </div>
                              <el-select v-model="PatientInfo[item.col_code]" v-else-if="item.valuetype=='3'"  v-show="item.visibled"  :ref="item.col_code" onkeydown="if(event.keyCode==9){event.returnValue=false;} " @keyup.tab.native="EnterEvent(item.col_code)"   @change="inputChangeEvent($event,item.col_code)" >
                              <!-- <el-option v-for="item in item.col_code" :key="item" :value="item" :label="item"></el-option> -->
                              <el-option v-for="(item,index) in popdropdwon_Options[item.col_code]" :key="index" :value="item.key" :label="item.value" ></el-option>
                              </el-select>
                              <el-input v-model="PatientInfo[item.col_code+'name']" v-else-if="item.valuetype=='5'" type="text" size="mini" :ref="item.col_code" v-show="item.visibled" :readonly="item.noedit"   @keyup.enter.native="EnterEvent(item.col_code)" @keyup.space.native="SpaceEvent(item.col_code)" @keyup.up.native="InputMove(0, item.col_code)" @keyup.down.native="InputMove(1, item.col_code)"  @focus="InputFocus(item.col_code)" @dblclick.native="inputdblEvent(item.col_code)" @change="popinputchange($event,item.col_code)" ></el-input>
                              <!-- <el-date-picker v-model="PatientInfo[item.col_code]" v-else-if="item.valuetype==='7'" v-show="item.visibled" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"  align="right" size="mini" :ref="item.col_code"></el-date-picker> -->
                              <div   v-else-if="item.valuetype==='7'">
                              <el-date-picker v-model="PatientInfo[item.col_code]" v-if="item.col_code=='smp_registerdate'" size="mini" align="right"    :clearable="false" v-show="item.visibled"   value-format="yyyy-MM-dd"    :disabled="true" :ref="item.col_code"  style="width:120px;"  onkeydown="if(event.keyCode==9){event.returnValue=false;} "  @keyup.enter.native="EnterEvent(item.col_code)"  ></el-date-picker>
                                  <!-- <el-date-picker v-model="PatientInfo[item.col_code]" v-if="item.col_code!='smp_registerdate'" size="mini"   v-show="item.visibled"  :clearable="false"  prefix-icon ="false"  type="datetime" value-format="yyyy-MM-dd HH:mm:ss"    :ref="item.col_code" style="width:120px;"  onkeydown="if(event.keyCode==9){event.returnValue=false;} " @keyup.tab.native="EnterEvent(1,item.col_code)" @keyup.enter.native="EnterEvent(item.col_code)" @keyup.up.native="InputMove(0, item.col_code)" @keyup.down.native="InputMove(1, item.col_code)" :disabled="!item.enabled" @focus="InputFocus(item.col_code)"    ></el-date-picker>
                                  -->
                                  <el-date-picker v-model="PatientInfo[item.col_code]" v-else-if="item.col_code!='smp_registerdate'" class="smpPicker" style="width:100%"  v-show="item.visibled" size="mini" :ref="item.col_code" type="datetime"  value-format="yyyy-MM-dd HH:mm:ss"  @keyup.enter.native="EnterEvent(item.col_code)" @keyup.up.native="InputMove(0,item.col_code)" @keyup.down.native="InputMove(1,item.col_code)"  @focus="InputFocus(item.col_code)"  ></el-date-picker>
                              </div>
                          </td>
                          </span>
                      </tr>
                      </table>
              </div>
              <div style="float:left;width:100%;">
                  <table style="float:right">
                      <!-- <tr>
                          <td>
                              <el-button icon="el-icon-search" type="primary" v-has="'PINQUERY'" @click="smpRegisterQuery()">查询</el-button>
                          </td>
                          <td style="align:left">
                              <el-button icon="el-icon-delete" v-has="'PDELETE'" @click="BtnDelete()" >删除</el-button>
                          </td>
                          <td style="text-align:left">
                              <el-button icon="el-icon-refresh-right" @click="BtnPrint()">打印</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-upload2" v-has="'PEXPORT'" @click="BtnExport()">导出</el-button>
                          </td>

                      </tr> -->
                  </table>
              </div>
          </div>
      </div>
      <div class="pagecenter">

         <vxe-table  :data.sync="RegisterTableData" border fit  height="auto" header-align="center" align="center" highlight-current-row scroll  ref="xTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe  >
              <vxe-table-column v-if="false" field="smp_registerid" title="标本登记id"  width="40px"></vxe-table-column>
              <!-- <vxe-table-column field="status" title="状态" width="50px" :formatter="registerStatusDisplay" :filters="[{label: '登记', value: '10'},{label: '打印', value: '20'},{label: '入库', value: '30'},{label: '使用', value: '40'},{label: '作废', value: '90'}]" ></vxe-table-column> -->
              <vxe-table-column field="status" title="登记状态" width="60px" :formatter="registerStatusDisplay" ></vxe-table-column>
              <vxe-table-column field="smp_registerno" title="登记序号" width="80px"></vxe-table-column>
              <vxe-table-column field="pat_no" title="病人号" width="60px"></vxe-table-column>
              <vxe-table-column field="pat_cardno" title="就诊卡号" width="80px"></vxe-table-column>
              <vxe-table-column field="pat_name" title="病人姓名" width="80px"></vxe-table-column>
              <vxe-table-column v-if="false" field="pat_sex" title="性别" width="40px"></vxe-table-column>
              <vxe-table-column field="pat_sexname" title="性别" width="40px"></vxe-table-column>
              <vxe-table-column field="pat_birth" title="病人生日" width="80px"></vxe-table-column>
              <vxe-table-column field="pat_agestr" title="年龄" width="40px"></vxe-table-column>
              <!-- <vxe-table-column field="pat_agestrname" title="年龄" width="40px"></vxe-table-column> -->
              <vxe-table-column field="pat_ageyear" title="岁数" width="40px"></vxe-table-column>
              <vxe-table-column v-if="false" field="pat_typecode" title="病人类型" width="80px"></vxe-table-column>
              <vxe-table-column field="pat_typecodename" title="病人类型" width="80px"></vxe-table-column>
              <vxe-table-column field="pat_address" title="病人联系地址" width="150px"></vxe-table-column>
              <vxe-table-column field="pat_nation" title="国籍" width="40px"></vxe-table-column>
              <vxe-table-column field="pat_idcardno" title="身份证/护照" width="250px"></vxe-table-column>
              <vxe-table-column field="pat_height" title="身高" width="40px"></vxe-table-column>
              <vxe-table-column field="weight" title="体重" width="40px"></vxe-table-column>
              <vxe-table-column field="abo_bldtype" title="abo血型" width="80px"></vxe-table-column>
              <vxe-table-column field="rh_bldtype" title="rh血型" width="80px"></vxe-table-column>
              <vxe-table-column v-if="false" field="req_deptno" title="申请科室" width="80px"></vxe-table-column>
              <vxe-table-column field="req_deptnoname" title="申请科室" width="80px"></vxe-table-column>
              <vxe-table-column field="pat_class" title="病人分类" width="80px"></vxe-table-column>
              <vxe-table-column field="pat_sourcetype" title="标本来源" width="80px"></vxe-table-column>
              <vxe-table-column field="hospitalname" title="外院名称" width="80px"></vxe-table-column>
              <vxe-table-column field="sourcecode" title="来源编号" width="80px"></vxe-table-column>
              <vxe-table-column field="familyornot" title="家族史" width="60px"></vxe-table-column>
              <vxe-table-column field="tumorsize" title="肿瘤大小" width="80px"></vxe-table-column>
              <vxe-table-column field="tumornumber" title="肿瘤个数" width="80px"></vxe-table-column>
              <vxe-table-column field="lymphanumber" title="淋巴结数" width="80px"></vxe-table-column>
              <vxe-table-column field="istransfer" title="远处转移" width="80px" :formatter="CheckStatusDisplay" ></vxe-table-column>
              <vxe-table-column field="tnm" title="tnm" width="60px"></vxe-table-column>
              <vxe-table-column field="isoperation" title="是否手术" width="80px" :formatter="CheckStatusDisplay"></vxe-table-column>
              <vxe-table-column field="postoperativedays" title="术后天数" width="80px"></vxe-table-column>
              <vxe-table-column field="operationdate" title="手术日期" width="80px"></vxe-table-column>
              <vxe-table-column field="smpdate" title="留样日期" width="80px"></vxe-table-column>
              <vxe-table-column field="remarks" title="备注" width="40px"></vxe-table-column>
              <vxe-table-column field="smp_registeruser" title="登记人" width="80px"></vxe-table-column>
              <vxe-table-column field="pat_diag" title="初诊" width="40px"></vxe-table-column>
              <vxe-table-column field="smp_registerdate" title="登记日期" width="100px"></vxe-table-column>
              <vxe-table-column field="originbarcode" title="检验条码" width="80px"></vxe-table-column>
              <vxe-table-column field="pathology1" title="肉眼所见" width="80px"></vxe-table-column>
              <vxe-table-column field="pathology2" title="镜下所见" width="80px"></vxe-table-column>
              <vxe-table-column field="pathology3" title="免疫组化" width="80px"></vxe-table-column>
              <vxe-table-column field="passagecnt" title="传代次数" width="80px"></vxe-table-column>
              <vxe-table-column field="strains" title="菌株" width="40px"></vxe-table-column>
              <vxe-table-column field="strainsproperty" title="菌株属性" width="80px"></vxe-table-column>
              <vxe-table-column field="cellbatchno" title="细胞批号" width="80px"></vxe-table-column>
              <vxe-table-column field="passagenum" title="细胞代次编号" width="80px"></vxe-table-column>
              <vxe-table-column field="cellclass" title="细胞类别" width="80px"></vxe-table-column>
              <vxe-table-column field="celllevel" title="细胞等级" width="80px"></vxe-table-column>
              <vxe-table-column field="cellqcflag" title="细胞质控标志" width="80px"></vxe-table-column>
              <vxe-table-column field="diseases" title="疾病种类" width="80px"></vxe-table-column>
              <vxe-table-column field="reserve1" title="备用1" width="80px"></vxe-table-column>
              <vxe-table-column field="reserve2" title="备用2" width="80px"></vxe-table-column>
              <vxe-table-column field="reserve3" title="备用3" width="80px"></vxe-table-column>
              <vxe-table-column field="reserve4" title="备用4" width="80px"></vxe-table-column>
              <vxe-table-column field="reserve5" title="备用5" width="80px"></vxe-table-column>
              <vxe-table-column field="reserve6" title="备用6" width="80px"></vxe-table-column>
              <vxe-table-column field="reserve7" title="备用7" width="80px"></vxe-table-column>
              <vxe-table-column field="reserve8" title="备用8" width="80px"></vxe-table-column>
              <vxe-table-column field="reserve9" title="备用9" width="80px"></vxe-table-column>
              <vxe-table-column field="reserve10" title="备用10" width="80px"></vxe-table-column>

          </vxe-table>
      </div>
      <rm_ElementConfig ref="ElementConfig" :librid="selLibrid"  :tableDataColumn="tableDataColumn" :ConfigDetail="ConfigDetail" @configDefChange="configDefChange" @close="ConfigClose" ></rm_ElementConfig>
  </div>
</template>

<script type="text/javascript">
import { Promise } from "q"
import { invalid } from "moment"
import XE from "xe-utils" //引入工具类
import rm_ElementConfig from '../../../rmcompents/rm_ElementConfig';
export default {
  name: "SMP312",
  data() {
      return {
          startdate: XE.toDateString(new Date(), "yyyy-MM-dd"),//开始时间
          enddate: XE.toDateString(XE.getWhatDay(new Date(), 1), "yyyy-MM-dd"),//结束时间
          pickerOptions: {
              shortcuts: [
                  {
                      text: "今天",
                      onClick(picker) {
                          picker.$emit("pick", XE.toDateString(new Date(), "yyyy-MM-dd 00:00:00"));
                      },
                  },
              ],
          }, //日期配置将时间切换到当天
          selLibrid: "", //样本库ID
          selSmpLibrary_Options: [],//样本库下拉框
          ColTotalData: [],//输入字段控件初始化数组
          HisTdWidth:[], //动态label宽度
          PatientInfo: {}, //病人信息
          RegisterTableData: [],//登记VxeTable绑定数据源
          popdropdwon_Options: [],//样本库控件下拉框绑定数组
          tableDataColumn: [], //设置弹窗的全部列数据
          ConfigDetail: {}, //tab页配置选项 改成json对象，方便后续再增加选项
          trNum:0,//输入字段控件动态大小
          tdNum:0,//输入字段控件动态大小
          ColData: [],//输入字段控件排序
          popdatatype: "SMP210",//弹框属性
          Options: {}, //选项
          changekeyflag: false, //数据改变标志
          InputCodeArr: [], //ddl数据列表
          dialogTableVisible: false, //通用弹窗
      }
  },
  components: {  rm_ElementConfig },
  created() {
     this.ddlSmp_Library();
  },
  mounted() {

  },
  updated() {

  },
  methods: {
      LibridChange() {
          this.QueryCol();

      },
       ddlSmp_Library() {
          this.$tool
              .request({
                  url: "SMP/SMP1/SMP130",
                  method: "post",
                  data: {
                      action: "q_smp_library",
                      islibrtype: "",
                      showstatus: "",
                  },
              })
              .then((res) => {
                  if(res.length>0)
                  {
                      for (let index = 0; index < res.length; index++) {
                          var element = res[index];
                          if (element.librtype === 10) {
                              res.splice(index,1);
                              index--;
                          }
                      }
                      this.selSmpLibrary_Options = res;
                      this.selLibrid = this.selSmpLibrary_Options[0].librid;
                      this.QueryCol();
                  }

              });
      },
      QueryCol(init) {
          // console.log("🚀 ~ file: SMP210.vue ~ line 285 ~ QueryCol ~ this.selLibrid", this.selLibrid);
          this.$tool
              .request({
                  url: "SMP/SMP2/SMP210",
                  method: "post",
                  data: {
                      action: "q_smp210_input_col",
                      librid: this.selLibrid,
                  },
              })
              .then((res) => {
                  console.log("res", res);
                  if (res) {
                      this.tableDataColumn = res;
                      if (init === 1) {
                          return
                      }

                      this.ColData = [];
                      this.dataLoad();
                      this.ColTotalData = [];
                      res = res.filter((item) => item.visibled == true); //可显示
                      //过滤错误字段
                      res = res.filter(item => item.col_code != "emer_flag");
                      res = res.filter(item => {
                              return item.col_code == "smp_registeruser"||
                          item.col_code == "pat_no"||item.col_code == "pat_cardno"||
                          item.col_code == "pat_name"||item.col_code == "pat_sex"||
                          item.col_code == "strains"||item.col_code == "pat_diag"||
                          item.col_code == "remarks"||item.col_code == "pat_ageyear"||
                          item.col_code == "pat_typecode"||item.col_code == "pat_class"||
                          item.col_code == "familyornot"||item.col_code == "strainsproperty"||
                          item.col_code == "pathology"||item.col_code == "hospitalname"||
                          item.col_code == "tnm"||item.col_code == "lymphanumber"||
                          item.col_code == "tumorsize"||item.col_code == "tumornumber"||
                          item.col_code == "pathology1"||item.col_code == "sourcecode"||
                          item.col_code == "istransfer"||item.col_code == "isoperation"||
                          item.col_code == "postoperativedays"||item.col_code == "passagecnt" ;
                      }
                      );
                      //查询样本库登记---初始化输入字段表valuetype为3的下拉框Option绑定的数据
                      this.Load_DropdownAll(res);
                      //更新UI (初始化登记控件排版)
                      this.HisUI(res);

                      for (let i = 0; i < this.tableDataColumn.length; i++) {
                          if (this.tableDataColumn[i].default_val != "") {
                              this.Queryddl("SMP210_" + this.tableDataColumn[i].col_code, "1");
                          } else {
                              this.tableDataColumn[i].default_valname = "";
                          }
                      }

                      this.$nextTick(() => {
                          //查询样本登记表数据
                          this.smpRegisterQuery();

                      });
                  }
              })
              .catch((error) => {
                  this.$message.error("错误1:" + error);
                  console.log("error", error);
              });
      },
      async smpRegisterQuery() {

          console.log('smpRegisterQuery()当前时间: ',new Date());

          // let tempDateTime =
          this.$tool
              .request({
                  url: "SMP/SMP3/SMP312",
                  method: "post",
                  data: {
                      action: "smp_register_query",
                      keystr: '',
                      startdate:this.startdate ,
                      enddate:this.enddate ,
                      librid: this.selLibrid,
                      registerinfo:this.PatientInfo,
                  },
              })
               .then((res) => {
                  if (res) {
                      this.RegisterTableData = res.RegisterRData.Data;
                      if (this.RegisterTableData.length>0) {



                      }

                  }
              })
              .catch((error) => {
                  this.$message.error("错误1:" + error);
                  console.log("error", error);
              });

              //this.referenceDefault();
      },
       dataLoad()
      {
          this.InitPatientInfo();
      },
       //样本登记对象初始化
      InitPatientInfo()
      {
          //样本登记主表对象
          this.PatientInfo ={smp_registerid:null, librid:this.sellibrid, smp_registerdate:this.selectdate,smp_registerno:this.specno,pat_sourcetype:'', originbarcode:'', pat_no:null, pat_cardno:'',
           pat_name:'', pat_sex:'',pat_sexname:'', pat_birth:'', pat_agestr:'',pat_agestr:'', pat_typecode:'',pat_typecodename:'', pat_idcardno:'', smp_registeruser:'',status:'', pat_diag:'', pat_height:'', weight:'', abo_bldtype:'',
           rh_bldtype :'', req_deptno:'',req_deptnoname:'', pat_class:'', hospitalname:'', sourcecode:'', familyornot:'', pathology:'', pathology1:'', pathology2:'', pathology3:'',
            tumorsize:'', tumornumber:'', lymphanumber:'', istransfer:'', tnm:'', isoperation:'', postoperativedays:'', operationdate:'', smpdate:'', remarks:'', pat_phone:'',
            pat_address :'', pat_nation:'', passagecnt:'',strains :'', strainsproperty:'', pat_ageyear:'', antivirus:'', medicine:'', takemeddate:'',cellbatchno :'', passagenum:'',
             cellclass:'',celllevel :'',cellqcflag :'',diseases :'',reserve1 :'', reserve2:'', reserve3:'', reserve4:'', reserve5:'', reserve6:'', reserve7:'',
             reserve8:'',reserve9 :'', reserve10:''};

      },
      Load_DropdownAll(res)
      {
          //valuetype 为3的固定绑定值
          let  field_code ;
          for (let index = 0; index < res.length; index++) {
              const element = res[index];
              //初始化下拉框
              if (element.valuetype =='3') {
                  let stroption ;
                  //1 本院|2 外院 pat_sourcetype  标本来源
                  if (element.col_code=='pat_sourcetype') {
                      stroption = [{'key':'1','value':'本院'},{'key':'2','value':'外院'}];
                      this.popdropdwon_Options[element.col_code] = stroption;
                  }
                  //0 无|1 有|2 不详  familyornot  家族史
                  if (element.col_code=='familyornot') {
                      stroption = [{'key':'0','value':'无'},{'key':'1','value':'有'},{'key':'2','value':'不详'}];
                      this.popdropdwon_Options[element.col_code] = stroption;
                  }
                  //1 初级库|2 建系|3 主库  cellclass  细胞类别
                   if (element.col_code=='cellclass') {
                      stroption = [{'key':'1','value':'初级库'},{'key':'2','value':'建系'},{'key':'3','value':'主库'}];
                      this.popdropdwon_Options[element.col_code] = stroption;
                  }
                  //C C属|W W属|V V属  celllevel  细胞等级
                   if (element.col_code=='celllevel') {
                      stroption = [{'key':'C','value':'C属'},{'key':'V','value':'W属'}];
                      this.popdropdwon_Options[element.col_code] = stroption;
                  }
                  //1 合格|2 不合格  cellqcflag  细胞质控标志
                   if (element.col_code=='cellqcflag') {
                      stroption = [{'key':'1','value':'合格'},{'key':'2','value':'不合格'}];
                      this.popdropdwon_Options[element.col_code] = stroption;
                  }
              }
              //初始化单选框
              else if (element.valuetype =='1') {

              }

          }

      },
      //样本库查询UI设置
      HisUI(res)
      {
              //样本登记信息table的<tr>行数
              // var num = parseInt((this.$refs.xTableDiv.offsetHeight - 40) /28);
              var num = parseInt((160 - 40) /28); //
              this.trNum = num;

              //上一个 下一个排序绑定变量
              this.ColData = res.slice(0, res.length);
              //#region

              var data = [];
              //data2是 res中除了smp_registerdate 和 smp_registerno的对象数组
              var data2 = [];
              //需要初始化的控件
              for (let index = 0; index < res.length; index++) {
                  if (res[index].col_code==="smp_registerdate") {
                          //this.RegisterDate =res[index];
                  }
                  else if (res[index].col_code==="smp_registerno") {
                          //this.RegisterSeq =res[index];
                  }
                  else
                  {
                      data2.push(res[index]);
                  }
              }
              // console.log('OKOKOK',this.RegisterDate);

              //每个tr平均多少个字段
              var fieldLength = parseInt(data2.length/num);
              this.tdNum = fieldLength;
              //余数
              var fieldRemainder = data2.length%num;

              //表格綁定数据排序
              for (let k = 0; k <num; k++) {
                  let tempArray =[];
                  for (let j = 0; j < fieldLength; j++) {
                      let tempValue=[];
                      if(k==0)
                      {
                          tempValue =data2[j*num];
                      }
                      else{
                          tempValue =data2[j*num+k];
                      }
                      tempArray.push(tempValue);
                  }
                  if (k<fieldRemainder) {
                      tempArray.push(data2[num*fieldLength+k]);
                  }
                  data.push(tempArray);
              }
              for (let i = 0; i <num; i++) {
                  this.ColTotalData.push(data[i]);
              }


              this.HisTdWidth =[];
              //计算His Table每列Td Label宽度

              for (let index = 0; index < fieldLength; index++) {
                  let columnsWidth =0;

                      for (let index1 = 0; index1 <num; index1++) {
                          let tempnum = data[index1][index].col_label.length*12;
                          if (columnsWidth<tempnum) {
                              columnsWidth =tempnum;
                          }
                      }
                          if (index===0) {
                      //保持登记序号与内容列宽度对其
                      this.RegisterDateTitleWidth =columnsWidth;
                  }
                          if (index===1) {
                      //保持登记序号与内容列宽度对其
                      this.RegisterTitleWidth =columnsWidth;
                  }
                      if (index===2) {
                      //保持登记序号与内容列宽度对其
                      this.SampleBankTitleWidth =columnsWidth;
                  }
                  this.HisTdWidth.push(columnsWidth);
              }
              console.log('YEYEYEYEYE',this.HisTdWidth);
              let columnsRemainderWidth =0;
              //计算His Table每列Td Label宽度(余数)
              for (let RemainderIndex = fieldLength *num; RemainderIndex < data2.length; RemainderIndex++) {
                  if (columnsRemainderWidth<data2[RemainderIndex].col_label.length*12) {
                      columnsRemainderWidth =data2[RemainderIndex].col_label.length*12;
                  }
              }
              if(columnsRemainderWidth>0)
              {
                  this.HisTdWidth.push(columnsRemainderWidth);
              }
              //初始化滚动条的初始展开位置(保持好看)
              //this.initScrollPosition = this.$refs.SampleBankWidth.offsetLeft+ this.$refs.SampleBankWidth.offsetWidth+350;
              //#endregion
      },
      //样本登记表 状态字段显示
      registerStatusDisplay({cellValue}, row, rowIndex, column, columnIndex)
      {

          // [{label: '登记', value: '10'},{label: '打印', value: '20'},{label: '入库', value: '30'},{label: '使用', value: '40'},{label: '作废', value: '90'}]
          return cellValue === '10' ? '登记' : cellValue === '20' ? '打印': cellValue === '30' ? '入库': cellValue === '40' ? '使用': cellValue === '90' ? '作废' : ''
      },
       //样本登记表 是否显示
      CheckStatusDisplay({cellValue}, row, rowIndex, column, columnIndex)
      {
          return cellValue === '1' ? '是' :cellValue === '0'? '否':'';
      },
      //Enter控件响应编辑区移动到下一个控件(输入字段控件)
      EnterEvent(colcode,keytype) {
          // console.log("EnterEvent ", colcode);

          this.InputMove(1, colcode);
          //this.$refs.editedit.$el.focus();
      },
       InputMove(type, colcode) {
          //0上移1下移
          if (type == 1) {
              var num = 0;
              for (let i = 0; i < this.ColData.length; i++) {
                  if (this.ColData[i].col_code == colcode) num = i;
              }
              var nextitem = this.ColData[num + 1];
              num = num + 1;
              if (num < this.ColData.length && num > -1) {
                  while (!nextitem.enabled && num < this.ColData.length - 1) {
                      nextitem = this.ColData[num + 1];
                      num = num + 1;
                  }
                  //this.$refs[nextitem][0].focus();
                  if (this.$refs[nextitem.col_code][0]) {
                      if (nextitem.col_code.toUpperCase().indexOf("_DT") == -1 && nextitem.col_code.toUpperCase().indexOf("_DATE") == -1 && this.$refs[nextitem.col_code][0]['type']!="datetime") {
                          this.$nextTick(() => {


                              this.$refs[nextitem.col_code][0].focus();
                          });
                      } else {
                          console.log('我在picker的移动',this.$refs[nextitem.col_code][0]);
                          this.$refs[nextitem.col_code][0].$refs.reference.$refs.input.focus();
                          // this.$refs[nextitem.col_code][0].focus();
                          this.$refs[nextitem.col_code][0].hidePicker();
                      }
                  }
              } else {
                  this.$refs['pat_no'][0].select();
              }
          } else {
              var num = 0;
              for (let i = 0; i < this.ColData.length; i++) {
                  if (this.ColData[i].col_code == colcode) num = i;
              }
              var nextitem = this.ColData[num - 1];
              num = num - 1;
              if (num < this.ColData.length && num > -1) {
                  while (!nextitem.enabled && num > 0) {
                      nextitem = this.ColData[num - 1];
                      num = num - 1;
                  }
                  //this.$refs[nextitem][0].focus();
                  if (this.$refs[nextitem.col_code][0]) {
                      if (nextitem.col_code.toUpperCase().indexOf("_DT") == -1 && nextitem.col_code.toUpperCase().indexOf("_DATE") == -1) {
                          this.$nextTick(() => {

                              this.$refs[nextitem.col_code][0].focus();
                          });
                      } else {
                          this.$refs[nextitem.col_code][0].focus();
                          this.$refs[nextitem.col_code][0].hidePicker();
                      }
                  }
              } else {
                  this.$refs.barcode[0].select();
              }
          }
      },
      //输入字段弹框
      configDefChange({ row, colcode }) {
          var selitem = this.tableDataColumn.find((item) => item.col_code == colcode);
          if (selitem) {
              var index = this.tableDataColumn.indexOf(selitem);
              if (row != "") {
                  this.tableDataColumn[index].default_val = row.hidkey;
                  this.tableDataColumn[index].default_valname = row.hidname;
              } else {
                  this.tableDataColumn[index].default_val = "";
                  this.tableDataColumn[index].default_valname = "";
              }
          }
          this.$refs.ElementConfig.$refs.xTableColumn.loadData(this.tableDataColumn);
      },
      //关闭弹窗
       ConfigClose() {
          // this.GetOptions(this.rptunitid).then(() => {
          //     this.QueryCol();
          // });
      },
      //查询DDL公用后台方法
      Queryddl(colcode, type) {
           if (!colcode) colcode = this.popdatatype;
          if (this.InputCodeArr.filter(item => item.key == colcode).length == 0) {
             this.$tool
                  .request({
                      url: "ucent/ddl",
                      method: "post",
                      data: {
                          action: colcode,
                          librid: this.selLibrid
                      }
                  })
                  .then(res => {
                      if (!res.hasOwnProperty("errcode")) {
                          this.InputCodeArr.push({ key: this.popdatatype, list: res });
                          if (type) {
                              var selitem = this.tableDataColumn.find((item) => item.col_code == colcode.replace("SMP210_", ""));
                              if (selitem && res) {
                                  var valuename = res.Data.find((item) => item.hidkey == selitem.default_val);
                                  if (valuename) {selitem.default_val = valuename.hidname;
                                      this.PatientInfo[colcode.replace("SMP210_", "")] = valuename.hidkey;
                                      this.PatientInfo[colcode.replace("SMP210_", "") + "name"] = selitem.default_val;
                                  }
                                  else selitem.default_val = selitem.default_val;
                              }
                          }
                      }
                  });
          }
          else {
              if (type) {
                  var data = this.InputCodeArr.find((item) => item.key == colcode);
                  var selitem = this.tableDataColumn.find((item) => item.col_code == colcode.replace("LIS3_", ""));
                  if (selitem && data) {
                      var valuename = data.list.Data.find((item) => item.hidkey == selitem.default_val);
                      if (valuename) {selitem.default_val = valuename.hidname;
                                  this.PatientInfo[colcode.replace("SMP210_", "")] = valuename.hidkey;
                                  this.PatientInfo[colcode.replace("SMP210_", "") + "name"] = selitem.default_val;
                              }
                      else selitem.default_valname = selitem.default_val;
                  }
              }
          }
      },
      //input输入框双击事件
      inputdblEvent(colcode) {
          this.popdatatype = "SMP210_" + colcode;
          let selitem = this.tableDataColumn.find(item => item.col_code == colcode);
          if (selitem && selitem.noedit) {
              return;
          }
          if (colcode === "pat_agestr") {
              if (this.PatientInfo[colcode]) {
                  var re1 = new RegExp("\\d+(?=" + this.radiofatherunit + ")", "g");
                  var re2 = new RegExp("\\d+(?=" + this.radiosonunit + ")", "g");
                  var age1 = this.PatientInfo[colcode].match(re1);
                  var age2 = this.PatientInfo[colcode].match(re2);
                  if (age1) {
                      this.inputfatherage = age1[0];
                  } else {
                      this.inputfatherage = "";
                  }
                  if (age2) {
                      this.inputsonage = age2[0];
                  } else {
                      this.inputsonage = "";
                  }
                  this.reagestrch = this.PatientInfo[colcode];
              }

              this.dialogAgeVisible = true;
          } else if (colcode == "lab_advice") {
              //this.advicetxt = this.PatientInfo[colcode].replace(/\\n/g, "\n");
              this.QueryAdvice();
              if (localStorage.getItem("floatwindowstyle3")) this.floatwindowstyle3 = localStorage.getItem("floatwindowstyle3");
              this.dialogAdvicefloatwindowVisible = true;
          } else {
              this.popdatatype = "SMP210_" + colcode;
              this.dialogTableVisible = true;
          }
      },
      //焦点事件 valuetype == 5
       InputFocus(colcode) {
          this.popdatatype = "SMP210_" + colcode;
          this.Queryddl();
          console.log(this.InputCodeArr);
          console.log(this.$refs[colcode]);
          if (colcode == "specno") {
              this.$refs.specno.select();
          } else if (colcode == "lab_advice") {
              this.QueryAdvice();
              this.$refs[colcode][0].select();
          } else {
              if (colcode.toUpperCase().indexOf("_DT") == -1 && colcode.toUpperCase().indexOf("_DATE") == -1 && this.$refs[colcode][0]['type']!='datetime') {
                  this.$refs[colcode][0].select();
              } else {
                  this.$refs[colcode][0].focus();
              }
          }
      },
       //Input输入框控件类型为5的change事件
      popinputchange(value, type) {
          // if (this.Options.inputasreportuser == "0" && type != "rechk_user" && type != "report_user") {
          //     this.PatientInfo.report_username = this.exactusernamereport;
          //     this.PatientInfo.report_user = this.exactusernoreport;
          // }
          switch (type) {
              case "pat_agestr":
                  var reg = new RegExp("\\d{1,}(y|Y|岁|年){0,}\\d{0,}(m|M|月){0,}\\d{0,}(d|D|日){0,}\\d{0,}(h|H|小时){0,}\\d{0,}(f|F|分钟){0,}", "gi");
                  var regd = new RegExp("^\\d{1,}$", "gi");
                  var regda = new RegExp("\\d{1,}", "gi");
                  if (value.match(regd)) {
                      this.PatientInfo[type] = value + "岁";
                      this.PatientInfo["pat_ageyear"] = value - 0;
                  } else if (value.match(reg)) {
                      this.PatientInfo[type] =
                          value
                              .replace("y", "岁")
                              .replace("年", "岁")
                              .replace("Y", "岁")
                              .replace("m", "月")
                              .replace("M", "月")
                              .replace("d", "日")
                              .replace("D", "日")
                              .replace("h", "小时")
                              .replace("H", "小时")
                              .replace("f", "分钟")
                              .replace("F", "分钟") + "";
                      this.PatientInfo.pat_ageyear = this.ageTransform(this.PatientInfo.pat_agestr);
                  } else {
                      this.$confirm("无效的病人年龄!", "提示", {
                          confirmButtonText: "确定",
                          cancelButtonText: "取消",
                          focusCancelButton: false,
                          closeOnClickModal: false,
                          type: "warning"
                      })
                          .then(() => {})
                          .catch(() => {});
                  }
                  break;
              case "lab_advice":
                  var list = this.InputCodeArr.filter(item => item.key == this.popdatatype);
                  if (list.length > 0) {
                      var row = list[0].list.Data.filter(item => (item.txtinfo + "").toUpperCase() == (value + "").toUpperCase() || (item.txttitle + "").toUpperCase() == (value + "").toUpperCase() || (item.inputcode + "").toUpperCase() == (value + "").toUpperCase());
                      if (row.length > 0) {
                          this.PatientInfo[type] = row[0].txtinfo;
                      }
                  }
                  break;
              default:
                  let selitem = this.tableDataColumn.find(item => item.col_code == type);
                  if (selitem && selitem.noedit) {
                      return;
                  }
                  if (value.trim()) {
                      var list = this.InputCodeArr.filter(item => item.key == this.popdatatype);
                      if (list.length > 0) {
                          var row = list[0].list.Data.filter(item => (item.inputcode + "").toUpperCase() == (value + "").toUpperCase() || (item.hidkey + "").toUpperCase() == (value + "").toUpperCase());
                          if (row.length > 0) {
                              if (type == "rechk_user" || type == "report_user") {
                                  this.usercode = row[0].hidkey;
                                  this.username = row[0].hidname;
                                  this.userpwd = "";
                                  this.dialogLoginVisible = true;
                                  this.$nextTick(() => {
                                      this.$refs.loginpwd.focus();
                                  });
                              } else {
                                  this.PatientInfo[type + "name"] = row[0].hidname;
                                  this.PatientInfo[type] = row[0].hidkey;
                              }
                          } else {
                              if (type == "pat_sex" || type == "pat_typecode" || type == "specimen_code" || type == "rechk_user" || type == "report_user") {
                                  this.dialogTableVisible = true;
                              } else {
                                  var re = new RegExp("[\\u4e00-\\u9fa5]", "gi");
                                  if (!re.test(value)) {
                                      this.dialogTableVisible = true;
                                  }
                              }
                          }
                      }
                  } else {
                      this.PatientInfo[type] = "";
                  }
                  break;
          }
      },
      //空格按键
       SpaceEvent(type) {
          var val = this.PatientInfo[type + "name"];
          if (!val.replace(/\s*/g, "")) {
              this.inputdblEvent(type);
          }
      },
       //输入框控件类型为2改变事件
      inputChangeEvent(value, type) {
          if (!this.changekeyflag) {
              // if (this.Options.inputasreportuser == "0") {
              //     this.PatientInfo.report_username = this.exactusernamereport;
              //     this.PatientInfo.report_user = this.exactusernoreport;
              // }
              switch (type) {
                  case "pat_no":
                      // this.changekeyflag = true;
                      // this.ExecPatNoChange(value, type)
                      //     .then(() => {
                      //         this.changekeyflag = false;
                      //     })
                      //     .catch(() => {
                      //         this.changekeyflag = false;
                      //     });

                      break;
                  case "barcode":
                      this.changekeyflag = true;
                      // var hasdata = this.$refs.xTableList.tableFullData.filter(item => item.sampleno == this.specno);
                      // if (this.PatientInfo.barcode != this.oldbarcode && hasdata.length > 0) {
                      //     if (hasdata[0].pat_name || hasdata[0].pat_no || hasdata[0].pat_typecode) {
                      //     }
                      // }
                      // this.ExecBarcodeChange()
                      //     .then(() => {
                      //         this.changekeyflag = false;
                      //     })
                      //     .catch(() => {
                      //         this.changekeyflag = false;
                      //     });
                      break;
              }
          }
      },
      //弹出框关闭时自动保存
      popcommonclose() {
          var typecol = (this.popdatatype + "").replace("SMP210_", "");
          if (this.$refs[typecol]) {
              this.$refs[typecol][0].select();
          }
          if (typecol == "specimen_code") {
              var value = this.PatientInfo.specimen_codename;
              var list = this.InputCodeArr.filter(item => item.key == this.popdatatype);
              var row = list[0].list.Data.filter(item => (item.inputcode + "").toUpperCase() == (value + "").toUpperCase() || (item.hidkey + "").toUpperCase() == (value + "").toUpperCase() || item.hidname.toUpperCase() == value.toUpperCase());
              if (row.length == 0) {
                  this.PatientInfo.specimen_codename = "";
                  this.PatientInfo.specimen_code = "";
              }
          }
      },
       //公共组件change事件
      popchange(c, v, row) {
          if (this.Options.inputasreportuser == "0") {
              this.PatientInfo.report_username = this.exactusernamereport;
              this.PatientInfo.report_user = this.exactusernoreport;
          }
          if (this.popdatatype != "SMP210_report_user" && this.popdatatype != "SMP210_rechk_user") {
              var colcode = this.popdatatype.replace("SMP210_", "");
              this.PatientInfo[colcode] = c;
              this.PatientInfo[colcode + "name"] = v;
              this.dialogTableVisible = false;
              this.$refs[colcode][0].select();
          } else {
              this.usercode = c;
              this.username = v;
              this.userpwd = "";
              this.dialogLoginVisible = true;
              this.dialogTableVisible = false;
          }
      },
  },
}
</script>

<style scoped>
.pagetop {
  width: 100%;
  height: 210px;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  white-space: nowrap;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
  overflow-x: auto;
  white-space: nowrap;
}

.pagecenter {
  position: absolute;
  top: 215px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 0px;
  right: 405px;
  overflow: auto;
}

.middle-right {
  position: absolute;
  height: 100%;
  width: 400px;
  right: 0px;
}
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}
.table1style tr td {
  padding: 0px 2px 0px 5px;
}

::v-deep .vxe-table .vxe-body--column.col-orange {
  background-color: #f8f8f8;
}
::v-deep .el-input--suffix .el-input__inner {
  padding-right: 0px;
}
::v-deep .tableleft .el-icon-time:before {
  content: "";
}
::v-deep .tableleft .el-input--prefix .el-input__inner {
  padding-left: 5px;
}
::v-deep .tableleft .el-input--suffix .el-input__inner {
  padding-right: 0px;
}
</style>
